home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 2: Applications / Linux Cubed Series 2 - Applications.iso / utils / file / logiso.000 / logiso / Utils / install_dir < prev    next >
Encoding:
Text File  |  1995-03-24  |  3.8 KB  |  135 lines

  1. # !/bin/ksh
  2. USAGE=\
  3. 'USAGE: install_dir [ -d config_prefix ] dest_dir_path mount_path map_to_path
  4.    If dest_dir_path is actually a directory below mount_path, duplicate 
  5.    directories below map_to_path to make dest_dir_path be below
  6.    map_to_path.
  7. '
  8. # (C) Copyright 1995 by Michael Coulter.  All rights reserved.
  9. # Basically we create on or for a directory many simple links and then use
  10. # check_links or check_one_link to fix up the link.
  11. set -P # print absolut hw path
  12.  
  13. # Define std functions
  14.  
  15.    ISOFS_UTIL_DIR="${ISOFS_UTIL_DIR:-/usr/src/linux/fs/isofs/Utils}"
  16.    . "$ISOFS_UTIL_DIR/ksh_fns"
  17.  
  18. # Process parameters
  19.  
  20.    CONFIG_PREFIX=""
  21.    if [ $# -ge 2 -a "$1" = "-d" ]
  22.    then
  23.       shift  # done with -d
  24.       CONFIG_PREFIX="$1"; shift
  25.    fi
  26.    if [ $# -ne 3 ]
  27.    then
  28.       echo "$USAGE" >&2
  29.       echo "$0 Expected 3 parameters, got $#" >&2
  30.       exit 1
  31.    fi
  32.    DEST_DIR_PATH="$1"; shift
  33.    MOUNT_PATH="$1"; shift
  34.    MAP_TO_PATH="$1"; shift
  35.    if [ ! -d "$DEST_DIR_PATH" ]
  36.    then
  37.       echo "$USAGE" >&2
  38.       echo "$DEST_DIR_PATH is not a directory" >&2
  39.       exit 1
  40.    fi
  41.    if [ "$DEST_DIR_PATH" = "${DEST_DIR_PATH#$MAP_TO_PATH}" ]
  42.    then
  43.       if [ "$DEST_DIR_PATH" = '.' -o "$DEST_DIR_PATH" = '/' ]
  44.       then
  45.          exit 0
  46.       fi
  47.       echo "$USAGE" >&2
  48.       echo "$DEST_DIR_PATH is not below $MAP_TO_PATH" >&2
  49.       exit 1
  50.    fi
  51.  
  52. # Set variables
  53.  
  54.    TEMP_DIR="install_dir.$$"
  55.    HERE="$PWD"
  56.  
  57. # Do it
  58.  
  59.    ##echo "install_dir: $DEST_DIR_PATH"
  60.    check_cmd 1 cd "$DEST_DIR_PATH"
  61.    THERE="$(pwd -H)"
  62.    ##echo "install_dir: THERE is $THERE"
  63.    # If THERE is not below MOUNT_PATH, there is nothing to do
  64.    if [ "$THERE" != "${THERE#$MOUNT_PATH}" ]
  65.    then
  66.       # EQUIV= the mirror of THERE.
  67.       if [ "$MAP_TO_PATH" = "/" ]
  68.       then
  69.      EQUIV="${THERE#$MOUNT_PATH}"
  70.       else
  71.      EQUIV="${MAP_TO_PATH}${THERE#$MOUNT_PATH}"
  72.       fi
  73.       ##echo "install_dir: EQUIV is $EQUIV"
  74.  
  75.       # We need to install THERE.  Do we need to install its parent?
  76.       cd "$(dirname "$EQUIV")"
  77.       if [ "$PWD" != "${PWD#${MOUNT_PATH}}" ]
  78.       then
  79.          ##echo "install_dir: " install_dir "$(dirname "$EQUIV")"  "$MOUNT_PATH"  "$MAP_TO_PATH"
  80.          check_cmd 20 install_dir -d "$CONFIG_PREFIX" "$(dirname "$EQUIV")"  "$MOUNT_PATH"  "$MAP_TO_PATH"
  81.       fi
  82.       cd "$HERE"
  83.  
  84.       DEST_PARENT="$(dirname "$DEST_DIR_PATH")"
  85.       if [ "$DEST_PARENT" != "$(dirname "$EQUIV")" ]
  86.       then
  87.      # We need to install DEST_DIR_PATH.  Do we need to install its parent?
  88.      cd "$DEST_PARENT"
  89.      if [ "$PWD" != "${PWD#${MOUNT_PATH}}" ]
  90.      then
  91.         check_cmd 20 install_dir -d "$CONFIG_PREFIX" "$DEST_PARENT"  "$MOUNT_PATH"  "$MAP_TO_PATH"
  92.      fi
  93.       fi
  94.  
  95.       # Install EQUIV
  96.       if [ ! -d "$EQUIV" ]
  97.       then
  98.          ##echo "install_dir: Processing $DEST_DIR_PATH path $EQUIV " >&2
  99.          echo "should be a directory." >&2
  100.          exit 21
  101.       fi
  102.  
  103.       check_cmd 2 cd "$(dirname "$THERE")"
  104.       THERE_PARENT="$(pwd -H)"
  105.       cd "$HERE"
  106.       if [ -L "$EQUIV" ]
  107.       then
  108.          check_cmd 5 cd "$DEST_PARENT"
  109.          rm -f "$TEMP_DIR"
  110.          check_cmd 6 mkdir "$TEMP_DIR"
  111.          check_cmd 7 cd "$THERE"
  112.          for FILE in * .??* .[^.]
  113.          do
  114.             if [ -e "$FILE" -o -L "$FILE" ]
  115.             then
  116.                ##echo install_dir: ln -s "${THERE}/${FILE}" "${DEST_PARENT}/${TEMP_DIR}/${FILE}"
  117.                ln -s "${THERE}/${FILE}" "${DEST_PARENT}/${TEMP_DIR}/${FILE}"
  118.             fi
  119.          done
  120.          cd "$HERE"
  121.          check_cmd 8 rm -f "$EQUIV"
  122.          check_cmd 12 cd "$DEST_PARENT"
  123.          check_cmd 9 mv "$TEMP_DIR" "$EQUIV"
  124.          check_cmd 10 cd "$HERE"
  125.          ##echo install_dir: check_cmd 11 check_links -d "$CONFIG_PREFIX" "$EQUIV"
  126.          check_cmd 11 check_links -d "$CONFIG_PREFIX" "$EQUIV"
  127.       fi
  128.       if [ -L "$DEST_DIR_PATH" ]
  129.       then
  130.      check_cmd 13 rm -f "$DEST_DIR_PATH"
  131.      check_cmd 14 ln -s "$EQUIV" "$DEST_DIR_PATH"
  132.       fi
  133.    fi
  134.    cd "$HERE"
  135.